#include <iostream>
#include <string>
#include <unistd.h>
#include <fcntl.h>

int main() {
    std::string program_name;
    std::cout << "Please input the program name: ";
    std::cin >> program_name;
    pid_t id = fork();
    // 创建出子进程，让子进程运行对应的进程
    if (id == 0) {
        int fd = open("/dev/pts/1", O_RDWR);
        if (fd < 0) {
            perror("open");
            exit(1);
        }
        dup2(fd, STDOUT_FILENO);
        dup2(fd, STDERR_FILENO);
        dup2(fd, STDIN_FILENO);
        close(fd);
        ::execl(program_name.c_str(), program_name.c_str(), nullptr);

        perror("execl");
        exit(1);

    }

    return 0;
}